package com.imcode;

import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Properties;
import java.util.Set;

public class PropertiesDemo {
    public static void main(String[] args) throws IOException {
        //1.创建对象
        Properties prop = new Properties();
        //2.常用方法
        prop.setProperty("k1","Hello");// 设值
        System.out.println(prop.get("k1"));//hello // 取值

        Reader fr = new FileReader("D:\\file\\db.properties");
        prop.load(fr);

        System.out.println(prop.get("username"));//root
        System.out.println(prop.get("password"));//123456
        System.out.println(prop.get("k1"));//Hello

        System.out.println("---------------------");

        // 获取所有key的名称
        Set<String> set = prop.stringPropertyNames();
        for(String key : set){
            System.out.println(key);
        }
    }
}
